﻿#include"ConcurrentAlloc.h"
//#include"ObjectPool.h"

void MultThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 5; i++)
	{
		void* ptr = ConcurrentAlloc(6);
		v.push_back(ptr);
	}
	for (auto e : v)
	{
		ConcurrentFree(e);
	}
}
void MultThreadAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 5; i++)
	{
		void* ptr = ConcurrentAlloc(7);
		v.push_back(ptr);
	}
	for (auto e : v)
	{
		ConcurrentFree(e);
	}
}

void TestMultThread()
{
	std::thread t1(MultThreadAlloc1);
	std::thread t2(MultThreadAlloc2);
	t1.join();
	t2.join();
}
void TestConcurrentAlloc()
{
	void* p1 = ConcurrentAlloc(3);
	void* p2 = ConcurrentAlloc(4);
	void* p3 = ConcurrentAlloc(7);
	void* p4 = ConcurrentAlloc(5);
	void* p5 = ConcurrentAlloc(2);
	void* p6 = ConcurrentAlloc(2);

	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;

	ConcurrentFree(p1);
	ConcurrentFree(p2);
	void* p8= ConcurrentAlloc(7);

	ConcurrentFree(p3);
	ConcurrentFree(p4);
	ConcurrentFree(p5);

	ConcurrentFree(p8);

}
void TestConcurrentAlloc2()
{
	for (size_t i = 0; i < 1024; ++i)
	{
		void* p1 = ConcurrentAlloc(3);
		cout << p1 << endl;
	}
	void* p2 = ConcurrentAlloc(4);
	cout << p2 << endl;
}

void BigAlloc()
{
	void* p1 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p1);
	void* p2 = ConcurrentAlloc(129*8 * 1024);
	ConcurrentFree(p2);
}

//int main()
//{
//    //TestObjectPool();
//	//TestMultThread();
//	//BigAlloc();
//	TestConcurrentAlloc();
//    return 0;
//}

